import {get, postWithJson} from "@/api/requests";
import * as echarts from "echarts"

/**
 * 健康饮食搭配参数配置
 * @param params
 * @returns {Promise<*>}
 */
export async function fetch(params) {
    return get('hcmw/fetch', params);
}

export async function fetchOne(params) {
    return get('hcmw/fetchOne', params);
}

export async function add(params) {
    return postWithJson('hcmw/add', params);
}

export async function update(params) {
    return postWithJson('hcmw/update', params);
}

export async function drop(params) {
    return get('hcmw/drop', params);
}

export async function res(params) {
    return get('hcmw/res', params);
}

export async function act(params) {
    return get('hcmw/act', params);
}

export async function stop(params) {
    return get('hcmw/stop', params);
}

export async function updateMemHeatGap(params) {
    return get('hcmw/setMemHeatGap', params);
}

export async function updateMemWeight(params) {
    return postWithJson('hcmw/setMemWeight', params);
}

export async function exutTotDinner(params) {
    return get('hcmsed/chkTotDinner', params);
}

export async function exutMenuDinner(params){
    return get('hcmsed/makeDaysDinner', params);
}

export async function exutDayDinner(params) {
    return get('hcmsed/chkDayDinner', params);
}

export async function exutMemDinner(params) {
    return get('hcmsed/chkMemDinner', params);
}

export async function exutPrinter(params) {
    return get('print/expMemDinner', params);
}

// 会员餐品数据下载
export async function expMemDinnerExcel(params) {
    return get('hcmsed/expMemDinnerExcel', params);
}

export async function expDebugMemDinner(params) {
    return get('hcmsed/debugMemDinner', params);
}

export async function exutDayDinnerTot() {

}

export async function expClrCache() {
    return get('hcmsed/expClrCache')
}

export async function fetchProjectsOpts() {
    return get('hcmsed/fetchProjectsOpts')
}

export async function extSupplyPrinting(params) {
    return postWithJson('print/supplyPrinting', params);
}

export async function drawPie(myPieChart, res) {
    let pie = echarts.init(myPieChart);
    let opinion_legend = res['legend'];
    let opinion_data = res['opinion_data'];
    let option = {
        title: {
            text: res['title'],
            subtext: res['subtitle'],
            left: 'center',
            padding: [15, 15, 15, 15],
        },
        tooltip: {
            trigger: "item",
            formatter: "{a}<br/>{b}:{c} ({d}%)"
        },
        toolbox: {
            show: true,
            feature: {
                mark: {show: true},
                dataView: {show: true, readOnly: false},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            bottom: 10,
            padding: [15, 15, 15, 15],
            data: opinion_legend
        },
        series: [{
            name: "食材名称",
            type: "pie",
            radius: "70%",
            center: ["50%", "50%"],
            roseType: 'area',
            avoidLabelOverlap: true,
            itemStyle: {
                borderRadius: 8,
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: "rgba(0, 0, 0, 0.5)"
                },
            },
            data: opinion_data
        }]
    }
    pie.setOption(option);
    return pie
}